const neo4j = require('neo4j-driver')

const driver = neo4j.driver(
    'neo4j://139.186.157.99:7687', // Neo4j 数据库的连接地址
    neo4j.auth.basic('neo4j', 'Haoziwoaini1314..'), // 用户名和密码
    {
        encrypted: false,
        maxTransactionRetryTime: 30000,
        connectionTimeout: 30000,
    }
)

// 测试连接
async function testConnection() {
    try {
        // 创建会话并测试查询
        const session = driver.session()  // 简化会话创建
        
        try {
            const result = await session.run('MATCH (n) RETURN count(n) as count')
            console.log('Neo4j连接成功，当前节点数量:', result.records[0].get('count').toNumber())
        } finally {
            await session.close()
        }
    } catch (error) {
        console.error('Neo4j连接失败:', error)
    }
}

// 导出前先测试连接
testConnection()
    .then(() => console.log('Neo4j连接测试完成'))
    .catch(error => console.error('Neo4j连接测试失败:', error));

module.exports = driver